﻿package mortal.game.view.complain
{
    import __AS3__.vec.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.controls.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ComplainModule extends SmallWindow
    {
        private var _sumbitBtn:GButton;
        private var _txtPhone:GTextFiled;
        private var _txtHelp:GTextFiled;
        private var _txtLink:GLinkButton;
        private var _txtContent:GTextInput;
        private var _fitstEdit:Boolean = true;
        private var _padding:uint = 100;
        private var _currWidth:uint = 0;
        private var _verticalSpacing:uint = 90;
        private var _radioButtonGroup:RadioButtonGroup;
        private var _helpType:Array;
        private var _radioButtons:Vector.<GRadioButton>;
        private const _defaultcontent:String;
        private const _sendLiftTime:int = 10000;
        private static var _mySendTime:int = 0;

        public function ComplainModule(param1:ILayer = null)
        {
            this._helpType = [Language.getString(21386), Language.getString(21387), Language.getString(21388), Language.getString(21389), ""];
            this._defaultcontent = Language.getString(21390);
            super(param1);
            setSize(500, 380);
            title = Language.getString(21391);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            if (this._radioButtonGroup)
            {
                if (this._radioButtonGroup.getRadioButtonAt(4))
                {
                    this._radioButtonGroup.getRadioButtonAt(4).selected = true;
                }
            }
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            this._currWidth = 0;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.bg(10, 30, 490, 70, this));
            pushUIToDisposeVec(UIFactory.bg(10, 140, 490, 200, this));
            this._sumbitBtn = UIFactory.gButton(Language.getString(21392), 215, 0, 66, 22, this);
            this._sumbitBtn.y = 350;
            this._sumbitBtn.configEventListener(MouseEvent.CLICK, this.onSumbitContent);
            var _loc_1:* = GlobalStyle.textFormatBai;
            this._txtPhone = UIFactory.textField("", 10, 30, 490, 80, this, _loc_1);
            this._txtPhone.type = TextFieldType.DYNAMIC;
            var _loc_2:* = Language.getString(21393);
            if (ParamsConst.instance.gmInfo)
            {
                _loc_2 = ParamsConst.instance.gmInfo;
            }
            this._txtPhone.htmlText = _loc_2;
            this._txtLink = UIFactory.gLinkButton("", 430, 75, 54, 20, this, _loc_1);
            this._txtLink.htmlText = Language.getString(21394);
            this._txtLink.OverHtml = Language.getString(21395);
            this._txtLink.OutHtml = Language.getString(21396);
            this._txtLink.Url = ParamsConst.instance.gmHelpUrl;
            this._txtHelp = UIFactory.textField("", 10, 110, 490, 80, this, _loc_1);
            this._txtHelp.type = TextFieldType.DYNAMIC;
            this._txtHelp.htmlText = Language.getString(21397);
            this._txtContent = UIFactory.gTextInput(10, 140, 490, 200, this);
            this._txtContent.maxChars = 200;
            this._txtContent.htmlText = this._defaultcontent;
            this._txtContent.configEventListener(MouseEvent.CLICK, this.onTxtContentClick);
            this._radioButtonGroup = new RadioButtonGroup("GmComplain");
            this._radioButtons = new Vector.<GRadioButton>;
            this.createRadioButton(this._helpType[0], this._radioButtonGroup);
            this.createRadioButton(this._helpType[1], this._radioButtonGroup);
            this.createRadioButton(this._helpType[2], this._radioButtonGroup);
            this.createRadioButton(this._helpType[3], this._radioButtonGroup);
            this.createRadioButton(this._helpType[4], this._radioButtonGroup).visible = false;
            return;
        }// end function

        private function createRadioButton(param1:String, param2:RadioButtonGroup) : GRadioButton
        {
            var _loc_3:* = UIFactory.radioButton(param1, this._padding + this._currWidth, 110, 100, 20, this);
            _loc_3.setStyle("textFormat", GlobalStyle.textFormatBai);
            _loc_3.group = param2;
            this._currWidth = this._currWidth + this._verticalSpacing;
            _loc_3.groupName = "GmComplain";
            this._radioButtons.push(_loc_3);
            return _loc_3;
        }// end function

        override protected function setWindowCenter() : void
        {
            return;
        }// end function

        override protected function addWindowLine() : void
        {
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            super.disposeImpl(param1);
            this._sumbitBtn = this._sumbitBtn && this._sumbitBtn.dispose(param1) ? (null) : (null);
            this._txtHelp = this._txtHelp && this._txtHelp.dispose(param1) ? (null) : (null);
            this._txtPhone = this._txtPhone && this._txtPhone.dispose(param1) ? (null) : (null);
            this._txtContent = this._txtContent && this._txtContent.dispose(param1) ? (null) : (null);
            this._txtLink = this._txtLink && this._txtLink.dispose(param1) ? (null) : (null);
            if (this._radioButtonGroup)
            {
                if (this._radioButtons)
                {
                    _loc_2 = this._radioButtons.length;
                    _loc_3 = 0;
                    while (_loc_3 < this._radioButtons.length)
                    {
                        
                        this._radioButtons[_loc_3].dispose(param1);
                        _loc_3++;
                    }
                    this._radioButtons = null;
                }
                this._radioButtonGroup = null;
            }
            return;
        }// end function

        override protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            super.closeBtnClickHandler(event);
            this._fitstEdit = true;
            return;
        }// end function

        private function onTxtContentClick(event:MouseEvent) : void
        {
            if (this._fitstEdit)
            {
                this._txtContent.htmlText = "";
                this._fitstEdit = false;
            }
            return;
        }// end function

        private function onSumbitContent(event:MouseEvent) : void
        {
            var _loc_5:Array = null;
            var _loc_2:int = 1;
            var _loc_3:String = "";
            var _loc_4:String = "";
            if (this._radioButtonGroup.selection == null || this._radioButtonGroup.selection.label == "")
            {
                MsgManager.showRollTipsMsg(Language.getString(21398));
                return;
            }
            _loc_3 = this._radioButtonGroup.selection.label;
            switch(_loc_3)
            {
                case this._helpType[0]:
                {
                    _loc_2 = 1;
                    break;
                }
                case this._helpType[1]:
                {
                    _loc_2 = 2;
                    break;
                }
                case this._helpType[2]:
                {
                    _loc_2 = 3;
                    break;
                }
                case this._helpType[3]:
                {
                }
                default:
                {
                    _loc_2 = 99;
                    break;
                    break;
                }
            }
            _loc_4 = this._txtContent.htmlText.replace(/[<]+[^>]*[>]""[<]+[^>]*[>]/g, "");
            if (this.CheakContent(_loc_4))
            {
                _loc_5 = new Array(_loc_2, _loc_3, _loc_4);
                Dispatcher.dispatchEvent(new DataEvent(EventName.ComplainSumbit, _loc_5));
            }
            return;
        }// end function

        private function CheakContent(param1:String) : Boolean
        {
            if (param1.length < 10)
            {
                MsgManager.showRollTipsMsg(Language.getString(21399));
                return false;
            }
            var _loc_2:* = FilterText.instance.setFilterColorStr(param1);
            if (_loc_2 != param1)
            {
                this._txtContent.htmlText = _loc_2;
                MsgManager.showRollTipsMsg(Language.getString(21400));
                return false;
            }
            if (_mySendTime != 0 && getTimer() - _mySendTime < this._sendLiftTime)
            {
                MsgManager.showRollTipsMsg(Language.getString(21401));
                return false;
            }
            _mySendTime = getTimer();
            this._fitstEdit = true;
            return true;
        }// end function

    }
}
